package com.cloudkinto.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.cloudkinto.bo.stock.*;
import com.cloudkinto.dto.home.StockInWhDto;
import com.cloudkinto.dto.stock.NormalInputShelfDto;
import com.cloudkinto.dto.stock.RelenishmentPlanAllDto;
import com.cloudkinto.dto.stock.TransferInputShelfDto;
import com.cloudkinto.dto.stock.adjust.box.BoxCellDto;
import com.cloudkinto.dto.stock.adjust.box.BoxCellStockDto;
import com.cloudkinto.dto.stock.adjust.box.BoxForAdjustDto;
import com.cloudkinto.dto.stock.adjust.sku.SkuCellDto;
import com.cloudkinto.dto.stock.adjust.sku.SkuCellStockDto;
import com.cloudkinto.dto.stock.back.OrderReturnStockDto;
import com.cloudkinto.dto.stock.defective.SkuRackCountDto;
import com.cloudkinto.dto.stock.defective.SkuStockForPickDto;
import com.cloudkinto.dto.stock.defective.SkuStockTotalDto;
import com.cloudkinto.dto.stock.query.*;
import com.cloudkinto.dto.stock.rent.StockAgeDto;
import com.cloudkinto.entity.ProductStockDo;
import com.cloudkinto.entity.ReplenishmentPlanDo;
import com.cloudkinto.entity.ReplenishmentPlanOrderDo;
import com.cloudkinto.vo.stock.PlatformSkuStockDto;
import com.cloudkinto.vo.stock.ProductTransportVo;
import com.cloudkinto.vo.stock.ReplenishmentPlanVo;
import com.cloudkinto.vo.stock.StockLockingVo;
import org.apache.ibatis.annotations.MapKey;
import org.apache.ibatis.annotations.Param;

import java.util.Collection;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * Mapper 接口
 * </p>
 *
 * @author hua
 * @since 2024-10-28
 */
public interface ProductStockDao extends BaseMapper<ProductStockDo> {
    /**
     * 可用sku种类
     */
    int getCanUseSkuKind(String source, Long userId, Long companyId, Long whId, Long tenantId);

    /**
     * 在途箱库存
     */
    int getTransportBoxCount(String source, Long userId, Long companyId, Long whId, Long tenantId);

    /**
     * 在途产品库存
     */
    int getTransportSkuCount(String source, Long userId, Long companyId, Long whId, Long tenantId);

    /**
     * 在库库存
     */
    List<StockInWhDto> getStockInWh(String source, Long userId, Long companyId, Long whId, Long tenantId);

    //获取某一订单类型的已上架数量
    int getPutQty(Long productId, Long orderId, String orderType, Long companyId);

    List<OrderReturnStockDto> getReturnStockRecord(Long orderId, String orderType);

    List<TransferInputShelfDto> getTransferInputShelfData(
            @Param("pasIdList") List<Long> pasIdList,
            @Param("orderType") String orderType,
            @Param("type") Integer type
    );

    Collection<NormalInputShelfDto> getNormalInputSkuShelfData(
            @Param("pasIdList") List<Long> pasIdList,
            @Param("orderType") String orderType,
            @Param("type") Integer type
    );

    Collection<NormalInputShelfDto> getNormalInputBoxShelfData(
            @Param("pasIdList") List<Long> pasIdList,
            @Param("orderType") String orderType,
            @Param("type") Integer type
    );


    List<StockAgeDto> getStockAgeList();

    List<SkuStockPageDto> productListPageBySku(
            @Param("bo") ProductStockBySkuQueryBo bo
    );

    /**
     * 库存状态一览 日销量 可售天数 库存状态
     * @return
     */
    List<SkuStockDto> productBySku(@Param("map")Map<String, Object> map);

    List<ProductTransportVo> getTransportNumBySku(
            @Param("productIdList") List<Long> productIdList,
            @Param("whIdList") List<Long> whIdList
    );

    List<SkuCellStockPageDto> productListPageByLocation(
            @Param("bo") ProductStockByLocationQueryBo req
    );

    List<SkuCellStockPageDto> productListPageByLocation(
            @Param("bo") Map<String, Object> bo
    );

    List<BoxCellStockPageDto> boxListPageByLocation(
            @Param("bo") BoxStockByLocationQueryBo req
    );

    List<BoxTypeStockPageDto> boxListPageByType(
            @Param("bo") BoxStockByTypeQueryBo req);


    IPage<ComplexStockPageDto> complexStockPage(@Param("page") IPage<ComplexStockPageDto> page, @Param("map") Map<String, Object> map);

    List<ComplexStockPageDto> complexStockPage(@Param("map") Map<String, Object> map);


    ComplexStockTotalDto complexStockTotal(@Param("map") Map<String, Object> map);

    List<BoxCellStockDto> getBoxCellStock(List<String> boxTypeNumber, List<Long> rackIds, List<Long> companyIds, Long whId, Long tenantId);

    IPage<BoxForAdjustDto> getBoxListForAdjust(@Param("page") IPage<BoxForAdjustDto> page, @Param("map") Map<String, Object> map);

    List<BoxCellDto> getBoxCellList(List<String> boxTypeNumber, List<Long> rackIds, List<Long> companyIds, Long whId, Long tenantId);


    List<SkuCellStockDto> getSkuCellStock(List<Long> productIds, List<Long> rackIds, List<Long> companyIds, Integer stockAttribute, Long whId, Long tenantId);


    List<SkuCellDto> getSkuCellList(List<Long> productIds, List<Long> rackIds, List<Long> companyIds, Long whId, Long tenantId);

    List<SkuRackCountDto> getSkuRackCountList(List<Long> productIds, Long whId, Long companyId);


    int updateStockById(Long id);

    List<SkuStockForPickDto> getStockForPickList(@Param("map") Map<String, Object> map);

    IPage<SkuStockTotalDto> getSkuStockTotalList(@Param("page") IPage<SkuStockTotalDto> page, @Param("map") Map<String, Object> map);

    List<SkuStockTotalDto> getSkuStockTotalList(@Param("map") Map<String, Object> map);

    List<StockLockingVo> getProductLockingStockDetail(@Param("bo") ProductStockLockingQueryBo bo);

    List<StockLockingVo> getBoxLockingStockDetail(@Param("bo") BoxStockLockingQueryBo bo);


    List<PlatformSkuStockDto> getPlatformSkuStockList(List<String> platforms, List<String> platformSkuList, List<String> parentSkuList, Integer inventoryLink, List<Long> storeIdList);


    void insertBatchReplenishmentPlan(List<ReplenishmentPlanDo> insertList1);



    List<ReplenishmentPlanDo> supplementPlanListPage(@Param("map")Map<String, Object> map);

    List<ReplenishmentPlanDo> selectByIds(List<Long> ids);

    void insertReplenishmentPlanDo(ReplenishmentPlanDo replenishmentPlanDo);




    List<ReplenishmentPlanVo>   selectReplenishmentOrderVo(@Param("map") Map map);

    String selectCreator(Long userId);

    void insertReplenishmentOrder(ReplenishmentPlanOrderDo orderDo);


    void updateBatchSingleReplenishmentPlan(List<ReplenishmentPlanDo> replenishmentPlanDos);

    void updateBatchStatus(List<Long> ids);

    void insertReplenishmentPlanOrder(ReplenishmentPlanVo newReplenishmentPlanVo);

    void insertNewOrder(ReplenishmentPlanOrderDo replenishmentPlanOrderDo);

    void insertBatch(List<ReplenishmentPlanDo> planDoList);

}
